﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace FlowNodeFramework.UC
{
    /// <summary>
    /// UDrawer.xaml 的交互逻辑
    /// </summary>
    public partial class UDrawer : UserControl
    {
        public UDrawer()
        {
            InitializeComponent();
            t1.X = -ContentWidth;
        }

        #region 依赖属性
        public string Title
        {
            get { return (string)GetValue(TitleProperty); }
            set { SetValue(TitleProperty, value); }
        }

        public static readonly DependencyProperty TitleProperty =
            DependencyProperty.Register("Title", typeof(string), typeof(UDrawer), new PropertyMetadata("标题"));


        public object Content
        {
            get { return (object)GetValue(ContentProperty); }
            set { SetValue(ContentProperty, value); }
        }

        public static readonly DependencyProperty ContentProperty =
            DependencyProperty.Register("Content", typeof(object), typeof(UDrawer), new PropertyMetadata(""));



        public double ContentWidth
        {
            get { return (double)GetValue(ContentWidthProperty); }
            set { SetValue(ContentWidthProperty, value); }
        }

        public static readonly DependencyProperty ContentWidthProperty =
            DependencyProperty.Register("ContentWidth", typeof(double), typeof(UDrawer), new PropertyMetadata(480d));

        #endregion

        #region 本地事件
        private void Close_Button_Click(object sender, RoutedEventArgs e)
        {
            this.Visibility = Visibility.Collapsed;
        }

        private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.Visibility = Visibility.Collapsed;
        }

        private void UserControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (Visibility == Visibility.Visible)
            {
                DoubleAnimation Animation = new DoubleAnimation();
                Animation.From = -ContentWidth;
                Animation.To = 0;
                Animation.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut };
                t1.BeginAnimation(TranslateTransform.XProperty, Animation);
            }
        }
        #endregion
    }
}
